import common from '@/assets/js/mmk_common.js'
function pay (mallname, order_sn, price, sb_type) {
    //支付方法
    wx.login({
        //获取openid
        success: function (result) {
            common.fly_post(
                'api/v4_5/minapp/info',
                {
                    code: result.code
                },
                response => {
                    let res = response.data
                    fly
                        .post('api/v4_5/payment/wechatpay_miniapp_submit', {
                            //预支付
                            openid: res.openid,
                            body: mallname,
                            order_sn: order_sn,
                            total: price,
                            submit_type: sb_type
                        })
                        .then(msg => {
                            wx.hideLoading()
                            let res = msg.data
                            if (res.status_code == 0) {
                                wx.requestPayment({
                                    timeStamp: res.data.timeStamp,
                                    nonceStr: res.data.nonceStr,
                                    package: res.data.package,
                                    signType: 'MD5',
                                    paySign: res.data.paySign,
                                    success: function (res) {
                                        console.log("支付成功");
                                        if (sb_type == 'project') {
                                            //项目支付成功跳转到预约列表
                                            wx.redirectTo({
                                                url: '/pages/package_projects/booking_success/main?status=1'
                                            })
                                        } else if (sb_type == 'shop') {
                                            wx.redirectTo({
                                                url: '/pages/package_projects/pay_success/main'
                                            })
                                        }
                                    },
                                    fail: function (res) {
                                        wx.navigateBack({
                                            delta: 2
                                        });
                                    }
                                })
                            } else {
                                _this.isdisabled = false
                                wx.hideLoading()
                                wx.showToast({
                                    title: res.message,
                                    icon: 'none',
                                    duration: 2000,
                                    mask: true
                                })
                                return false
                            }
                        })
                }
            )
        }
    })
}

export default pay
